<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    .container {
        width: 100%;
    }
</style>
<style>
    .selectInput {
        position: relative;
        width: 100%;
        min-width: 100px;
    }

    .selectInput .flavorSelect {
        position: absolute;
        width: 100%;
        padding: 0 10px;
        border-radius: 3px;
        border: solid 1px #FF903D;
        line-height: 30px;
        text-align: center;
        background: #fff;
        top: 50px;
        z-index: 99;
    }

    .selectInput .flavorSelect .items {
        cursor: pointer;
        display: inline-block;
        width: 100%;
        line-height: 35px;
        border-bottom: solid 1px #f4f4f4;
        color: #666;
    }

    .selectInput .flavorSelect .none {
        font-size: 14px;
    }

    #food-add-app .uploadImg .el-form-item__label::before {
        content: '*';
        color: #F56C6C;
        margin-right: 4px;
    }
    .img-upload{
        position: absolute;
        top: 0;
        left: 0;
    }
    .select{
        width: 293px;
        height: 40px;
        border: 1px solid #d8dde3;
        border-radius: 4px;
        appearance:none;
        -moz-appearance:none;
        -webkit-appearance:none;
        color: #818693;
    }
    .select option{
        color: #ffc200;
    }
    .select:hover{
        border: 1px solid #d8dde3;
    }
</style>


<div id="food-add-app" class="addBrand-container">
    <div class="container">
        <form class="el-form demo-ruleForm el-form--inline">
            <div>
                <div class="el-form-item is-required">
                    <label for="name" class="el-form-item__label" style="width: 180px;">优惠券名称:</label>
                    <div class="el-form-item__content">
                        <div class="el-input">
                            <input type="text" autocomplete="off" id="couponName" placeholder="请填写优惠券名称" maxlength="20" class="el-input__inner">
                        </div>
                    </div>
                </div>
                <div class="el-form-item is-required"><label for="parentId" class="el-form-item__label" style="width: 180px;">优惠金额:</label>
                    <div class="el-form-item__content">
                        <div class="el-select">
                            <div class="el-input el-input--suffix">
                                <input type="text" autocomplete="off" id="couponPrice" placeholder="请填写优惠券金额" maxlength="20" class="el-input__inner">
                            </div>
                            <div class="el-select-dropdown el-popper" style="display: none; min-width: 293px;">
                                <div class="el-scrollbar" style="display: none;">
                                    <div class="el-select-dropdown__wrap el-scrollbar__wrap" style="margin-bottom: -17px; margin-right: -17px;">
                                        <ul class="el-scrollbar__view el-select-dropdown__list"></ul>
                                    </div>
                                    <div class="el-scrollbar__bar is-horizontal">
                                        <div class="el-scrollbar__thumb" style="transform: translateX(0%);"></div>
                                    </div>
                                    <div class="el-scrollbar__bar is-vertical">
                                        <div class="el-scrollbar__thumb" style="transform: translateY(0%);"></div>
                                    </div>
                                </div>
                                <p class="el-select-dropdown__empty">
                                    无数据
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div>
                <div class="el-form-item is-required">
                <label for="title" class="el-form-item__label" style="width: 427px;">优惠条件:</label>
                <div class="el-form-item__content">
                    <div class="el-input">
                        <input type="text" autocomplete="off" id="couponTerm" placeholder="请设置优惠条件" class="el-input__inner">
                    </div>
                </div>
            </div>
           <!-- <div class="el-form-item"><label class="el-form-item__label" style="width: 180px;">口味做法配置:</label>
                <div class="el-form-item__content">
                    <div class="el-form-item">
                        <div class="el-form-item__content">
                            <div class="flavorBox"><span class="addBut"> + 添加口味</span></div>
                        </div>
                    </div>
                </div>
            </div>-->
            <div></div>
            <div>
                <div class="el-form-item is-required">
                    <label for="price" class="el-form-item__label" style="width: 180px;">开始时间:</label>
                    <div class="el-form-item__content">
                        <div class="el-input">
                            <input type="date" id="startTime" placeholder="请设置优惠开始时间" class="el-input__inner">
                        </div>
                    </div>
                </div>
                <label for="title" class="el-form-item__label" style="width: 180px;">结束时间:</label>
                <div class="el-form-item__content">
                    <div class="el-input">
                        <input type="date" id="endTime" autocomplete="off" placeholder="请设置优惠结束时间" class="el-input__inner">
                    </div>
                </div>
            </div>
            <div class="subBox address">
                <div class="el-form-item">
                    <div class="el-form-item__content">
                        <button type="button" class="el-button el-button--default">
                            <span> 取消 </span>
                        </button>
                        <button type="button" class="el-button el-button--primary">
                            <span>保存 </span>
                        </button>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-layer layui-layer-page layui-layer-molv layer-anim" id="menuLayer" type="page" times="2" showtime="0" contype="object"
             style="z-index:59891016; width: 300px; height: 450px; top: 100px; left: 640px; display:none">
            <div class="layui-layer-title" style="cursor: move;">选择菜单</div>
            <div class="layui-layer-content" style="height: 358px;">
                <div style="padding: 10px;" class="layui-layer-wrap">
                    <ul id="menuTree" class="ztree"></ul>    <!-- 动态加载树 -->
                </div>
            </div>
            <span class="layui-layer-setwin"> <a class="layui-layer-ico layui-layer-close layui-layer-close1 btn-cancel" ></a></span>
            <div class="layui-layer-btn layui-layer-btn-">
                <a class="layui-layer-btn0 btn-confirm">确定</a>
                <a class="layui-layer-btn1 btn-cancel">取消</a>
            </div>
        </div>
    </div>
</div>

<script src="api/food/food.js"></script>
<script type="text/javascript" src="../bower_components/ztree/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="../bower_components/layer/layer.js"></script>
<script>
 
    $(function(){
        $(".el-button--default").on("click",backToCouponList);//取消返回主界面
        $(".el-button--primary").on("click",saveAddOrUpdate);//添加或者修改
        var data = $("#cIframe").data("couponRow");
        if(data)doInitEditFormData($("#cIframe").data("couponRow"));
    })

    /**
     * 如果是修改的话拿到要填充的数据
     */
    function doInitEditFormData(data) {
        $("#couponName").val(data.couponName);
        $("#couponPrice").val(data.couponMoney);
        $("#couponTerm").val(data.couponTerm);
        $("#startTime").val(data.startTime);
        $("#endTime").val(data.endTime);
    }

    /**
     * 提交添加或者修改结果
     */
    function saveAddOrUpdate() {
        //id itemid imgid
        //id imgurl
        debugger
        var insertUrl = "coupon/saveCouponData";//保存菜单url
        var updateUrl = "coupon/updateCouponData";//修改
        var params = doGetEditFormData();
        var couponRow = $("#cIframe").data("couponRow");
        var url=couponRow?updateUrl:insertUrl;
        if(couponRow)params.id=couponRow.id;
        if (!params.couponName || !params.couponMoney || !params.couponTerm){
            commonShowTips("请将表单信息填写完整！！");
            return;
        }
        $.get(url, params, function(result) {
            if (result.state == 1) {
                commonShowTips(result.message);
                backToCouponList();
            } else {
                commonShowTips(result.message);
            }
        })
    }

    /**
     *表单数据封装
     */
    function doGetEditFormData() {
        debugger
        var params={
            couponName : $("#couponName").val(),
            couponMoney : $("#couponPrice").val(),
            couponTerm : $("#couponTerm").val(),
            startTime : $("#startTime").val(),
            endTime : $("#endTime").val()
        }
        return params;
    }

    /**
     * 取消返回优惠券主界面
     */
    function backToCouponList() {
        $("#cIframe").data("couponId","");
        $("#cIframe").load("coupon/list");
    }
</script>